var app = getApp();
Page({
    data:{
        curPage : "/zofui_sales/kfc/orderinfo",
        siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
		info : {},
        inited : false,
        options : {},
    },
    onLoad:function(options){
        var self = this;

        this.data.options = options;
        var zfid = options.zfid > 0 ? options.zfid : '';

        app.com.auth(function(user){
            var postdata = {
                op : 'orderinfo',
                id : options.id,
                zfid : zfid,
            };
            app.com.http('kfc','POST',postdata,0,false,'','',function(res){
                if(res.data && !res.data.errno){
                    var data = res.data.data;
                    self.setData({
                       sharedata : res.data.data.sharedata,
                       params : res.data.data.params,
                       info : res.data.data.info,
                       inited : true,
                    });
                    
                    wx.setNavigationBarTitle({
                        title:  res.data.data.params.title ? res.data.data.params.title : '订单',
                    });
                }else{
                    app.com.alert(res.data.message);
                }
            });
        });
        
    },
    onShareAppMessage : function(e){
        var self = this;
        return {
            title: self.data.sharedata.title,
            path: self.data.sharedata.path,
            imageUrl : '',
        }
    },
    onPullDownRefresh: function () {
        if( this.data.isdown ) return false;
        this.data.isdown = true;
        this.onLoad( this.data.options );
        this.data.isdown = false;
        wx.stopPullDownRefresh();
    },
    payNow : function( e ){
        var self = this;
        var postdata = {
            op : 'payorder',
            orderid : self.data.info.orderNo,
        };
        app.com.http('kfc','POST',postdata,0,true,'','',function(res){
            if (res.data && !res.data.errno) {
                
                wx.requestPayment({
                    'appId' : res.data.data.appId,
                    'timeStamp': res.data.data.timeStamp,
                    'nonceStr': res.data.data.nonceStr,
                    'package': res.data.data.package,
                    'signType': 'MD5',
                    'paySign': res.data.data.paySign,
                    'success': function (payres) {
                        if( payres.errMsg == 'requestPayment:ok' ){
                            app.com.toast('已支付完成','success',function(){
                                self.onLoad( self.data.options );
                            });
                        }
                    },
                    'fail': function (payres) {
                        app.com.toast('已取消支付','none');
                    }
                });


            }else{
                app.com.alert(res.data.message,function(){
                    app.com.backPage(options.zfid);
                });
            }
        });
        
    },
    copy(e){
        app.com.copy( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    },
    footNavigate(e){
        var url = e.currentTarget.dataset.url;
        wx.switchTab({
          url: url
        })
    },

})